# -*- coding:utf-8 -*-
# 鼠标拖拽
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get("http://sahitest.com/demo/dragDropMooTools.htm")


# 被拖拽的元素
target = driver.find_element(By.XPATH, '//*[@id="dragger"]')

# 拖拽的目标位置
item1 = driver.find_element(By.XPATH, '/html/body/div[2]')
item2 = driver.find_element(By.XPATH, '/html/body/div[3]')
item3 = driver.find_element(By.XPATH, '/html/body/div[4]')
item4 = driver.find_element(By.XPATH, '/html/body/div[5]')


action = ActionChains(driver)
time.sleep(3)

# 方法一：
action.drag_and_drop(target, item1).perform()
time.sleep(2)

# 方法二：
action.click_and_hold(target).move_to_element(item2).release().perform()
time.sleep(2)

# 方法三
action.click_and_hold(target).release(item3).perform()

